package com.example.star.service;

import com.example.star.entity.Favorite;
import com.example.star.entity.ShoppingCart;
import com.example.star.mapper.FavoriteMapper;
import com.example.star.mapper.ShoppingCartMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ShoppingCartService {
    @Autowired
    private ShoppingCartMapper shoppingCartMapper;
    public void saveShoppingCart(ShoppingCart shoppingCart) {
        shoppingCartMapper.insertShoppingCart(shoppingCart);
    }

    public List<ShoppingCart> getAllShoppingCarts() {
        return shoppingCartMapper.getAllShoppingCarts();
    }


    public List<ShoppingCart> getShoppingCartByuserName(String userName){
        return shoppingCartMapper.getShoppingCartByuserName(userName);
    }

    public List<ShoppingCart> getShoppingCartByPage(int page, int size) {
        int offset = (page - 1) * size;
        return shoppingCartMapper.getShoppingCartsByPage(offset, size);
    }

    public int getTotalShoppingCarts() {
        return shoppingCartMapper.getTotalShoppingCarts();
    }

    public void deleteShoppingCartById(int id) {
        shoppingCartMapper.deleteShoppingCartById(id);
    }

    // 分页查询指定用户的购物车信息
    public List<ShoppingCart> getShoppingCartsByUserPage(String userName, int page, int size) {
        int offset = (page - 1) * size;
        return shoppingCartMapper.getShoppingCartsByUserPage(userName, offset, size);
    }

    // 获取指定用户的购物车记录总数
    public int getTotalShoppingCartsByUser(String userName) {
        return shoppingCartMapper.getTotalShoppingCartsByUser(userName);
    }
}
